from base.base import Base
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
import time
class Page_TextAlarmSet(Base):

        
    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[7]')
    topnav_nav_locator = (By.XPATH,'//span[text()="短信告警设置"]')

    input_time_locator = (By.XPATH,'//input[@placeholder="开始日期"]')
    month_locator = (By.XPATH,'(//button[@class="ant-picker-month-btn"])[1]')
    start_month_locator = (By.XPATH,'//div[@class="ant-picker-cell-inner" and text()="6月"]')
    start_day_locator = (By.XPATH,'(//div[text()="1"])[1]')
    end_day_locator = (By.XPATH,'(//div[text()="28"])[3]')
    select_btn_locator = (By.XPATH,'//span[text()="查 询"]')
    reset_btn_locator = (By.XPATH,'//span[text()="重 置"]')
    list_locator = (By.XPATH,'//tbody//td[contains(@class,"ant-table-cell")]')
    site_input_locator = (By.XPATH,'(//input[@class="ant-select-selection-search-input"])[1]')
    site_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    type_input_locator = (By.XPATH,'//div[@class="ant-select ant-select-single ant-select-allow-clear ant-select-show-arrow"]')
    type_locator = (By.XPATH,'//div[@class="ant-select-item-option-content"]')
    textalarmset_locator = (By.XPATH,'//span[text()="短信告警配置"]')
    input_bit_locator = (By.XPATH,"//span[contains(concat(' ', normalize-space(@class), ' '), ' ant-radio ')]")
    input_sendkey_locator = (By.XPATH,'//input[@role="spinbutton"]')
    add_phonenumber_locator = (By.XPATH,'//button[@class="ant-btn ant-btn-dashed ant-btn-block"]')
    accept_site_locator = (By.ID,'form_item_scen_alarm_configs_1_all_region_code')
    accept_phonenumber_locator = (By.XPATH,'//input[@id="form_item_scen_alarm_configs_1_all_region_code"]//following::input')
    confirm_btn_locator = (By.XPATH,'//span[text()="确 定"]')
    test_locator = (By.XPATH,'//div[text()="天宝湾"]')


    def page_jump(self):
        action = ActionChains(self.driver)
        action.move_to_element(self.find(self.topnav_locator)).perform()
        action.click(self.find(self.topnav_nav_locator)).perform()

    def get_list(self):
        values = []
        elms = self.finds(self.list_locator)
        for elm in elms:
            values.append(self.get_text_elm(elm))
        return values

    def click_time_inputbox(self):
        self.click(self.input_time_locator)

    def click_month_inputbox(self):
        self.click(self.month_locator)

    def select_start_month(self):
        self.click(self.start_month_locator)

    def select_start_day(self):
        self.click(self.start_day_locator)

    def select_end_day(self):
        self.click(self.end_day_locator)

    def click_select_btn(self):
        self.click(self.select_btn_locator)
    
    def click_reset_btn(self):
        self.click(self.reset_btn_locator)

    def input_site(self,sitename):
        self.input(self.site_input_locator,sitename)

    def click_first_opt(self):
        self.click(self.site_locator)
        
    def click_first_opt_2(self):
        self.click(self.site2_locator)
       

    def click_type_input(self):
        self.click(self.type_input_locator)

    def select_tpye(self,id = 0):
        elms = self.finds(self.type_locator)
        self.click(elms[id])

    def click_textalarm_btn(self):
        self.click(self.textalarmset_locator)

    def click_input_bit(self,id):
        for index,elm in enumerate(self.finds(self.input_bit_locator)):
            if index == id:
                elm.click()
    
    def sendkey_input(self,id,number):
        for index,elm in enumerate(self.finds(self.input_sendkey_locator)):
            if index == id:
                elm.send_keys(Keys.CONTROL+'a')
                elm.send_keys(Keys.DELETE)
                elm.send_keys(number)
    
    def click_add__btn(self):
        self.click(self.add_phonenumber_locator)
    
    def input_accept_site(self,site):
        self.input(self.accept_site_locator,site)

    def input_accept_phone(self,number):
        self.input(self.accept_phonenumber_locator,number)

    def click_confirm_btn(self):
        self.click(self.confirm_btn_locator)
    
    